﻿/* 通过时间差来判断是键盘输入还是扫描输入 */
var KeyCode = { EnterKey: 13, DLE: 16, EscKey: 27, PageUpKey: 33, PageDownKey: 34, EndKey: 35, HomeKey: 36, LeftArrow: 37, UpArrow: 38, RightArrow: 39, DownArrow: 40, InsertKey: 45, DeleteKey: 46 }
var previous = 0;
var limit = 100;
var timeout_id;
var lockObj, tipObj; //文本框、提示控件（div/span）
var errMsg = "请使用扫描枪输入";
function error() {
    tipObj.innerHTML = errMsg;
    lockObj.value = "";
    lockObj.focus();
    previous = 0;
}
function lockInput(obj) {
    lockObj = obj;
    var dt = new Date().getTime();
    if (event.keyCode == KeyCode.DLE)
        return true;
    if (previous == 0) {
        previous = dt;
        timeout_id = setTimeout("error()", 100);
        return true;
    }
    else if (dt - previous > limit) {
        error();
        clearTimeout(timeout_id);
        return false;
    }
    else {
        previous = dt;
        clearTimeout(timeout_id);
    }
}